package com.atguigu.gmall.order.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.order.OrderInfo;
import com.atguigu.gmall.model.vo.order.OrderConfirmVo;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.atguigu.gmall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2024/10/7 8:20
 */
@RestController
@RequestMapping("/rpc/inner/order")
public class OrderRpcController {
    @Autowired
    OrderService orderService;
    @Autowired
    OrderInfoService orderInfoService;

    /**
     * @description:返回订单页精确数据
     * @author: chensiwei
     * @date: 2024/10/7 8:31
     * @param: []
     * @return: com.atguigu.gmall.common.result.Result<com.atguigu.gmall.model.vo.order.CartItemForOrderVo>
     **/
    @GetMapping("/confirm")
    public Result<OrderConfirmVo> getCartConfirmList(){
        OrderConfirmVo orderConfirmVo=orderService.getCartConfirmList();

        return Result.ok(orderConfirmVo);
    }
    @GetMapping("/amount")
    public Result<OrderInfo> getOrderInfoById(@RequestParam("orderId") Long orderId){
        OrderInfo orderInfo=orderInfoService.getOrderInfoById(orderId);
        return Result.ok(orderInfo);
    }
    @GetMapping("/paid")
    public Result updateStatusToPaid(@RequestParam("outTradeNo") String outTradeNo){
        orderInfoService.updateStatusToPaid(outTradeNo);

        return Result.ok();
    }
    @GetMapping("/checkstatus/{outTradeNo}")
    public Result checkOrderStatus(@PathVariable("outTradeNo")String outTradeNo){
        orderService.checkOrderStatus(outTradeNo);
        return Result.ok();
    }

}
